package com.mengshu.platform.web.serializer;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * <p>
 *     mvc 序列化配置
 * </p>
 *
 * @author liuning
 * @date 8:43 上午 2022/2/6
 */
@Configuration
public class WebSerializerConfig implements WebMvcConfigurer {


    // long类型精度丢失处理
    @Bean
    public HttpMessageConverter httpMessageConverter() {
        MappingJackson2HttpMessageConverter httpMessageConverter = new MappingJackson2HttpMessageConverter();
        ObjectMapper objectMapper = new ObjectMapper();
        httpMessageConverter.setObjectMapper(objectMapper);
        return httpMessageConverter;
    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        converters.add(1, httpMessageConverter());
    }
}
